package com.SparkCore.RDD.dep

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Spark02_RDD_Dep {
  def main(args: Array[String]): Unit = {

    val sparkConf = new SparkConf().setMaster("local").setAppName("WordCount1")
    val sc = new SparkContext(sparkConf)

    val lines: RDD[String] = sc.textFile("datas/1.txt")
    println(lines.dependencies)
    println("============================")
    val words: RDD[String] = lines.flatMap(_.split(" "))

    println(lines.dependencies)
    println("============================")
    val wordToOne = words.map((_, 1))

    println(lines.dependencies)
    println("============================")
    val wordToSum: RDD[(String, Int)] = wordToOne.reduceByKey(_ + _)

    println(lines.dependencies)
    println("============================")
    val array: Array[(String , Int)] = wordToSum.collect()
    array.foreach(println)
    sc.stop()
  }
}
